package com.yunling.qishi.macaca.utils;
/**
 * 用于数据库相关操作，主要为查询删除,增删改查
 * @author yunling.he
 *
 */

import java.io.Closeable;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class DbUtils {
	private static ComboPooledDataSource dataSource = new ComboPooledDataSource();
	
	public static Connection getConnection() throws SQLException{
		return dataSource.getConnection();
	}
	
	public static DataSource getDataSource(){
		return dataSource;
	}
	public static void closeAll(Connection conn,Statement st,ResultSet rs){
		try {
			conn.close();
			st.close();
			rs.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private static void closeC(Closeable...io){
		for(Closeable cl:io){
			if(cl!=null){
				try {
					cl.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
